package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BookTime;
import com.ruoyi.business.service.IBookTimeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 规定时间段Controller
 * 
 * @author liwenjing
 * @date 2021-05-20
 */
@RestController
@RequestMapping("/business/time")
public class BookTimeController extends BaseController
{
    @Autowired
    private IBookTimeService bookTimeService;

    /**
     * 查询规定时间段列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BookTime bookTime)
    {
        startPage();
        List<BookTime> list = bookTimeService.selectBookTimeList(bookTime);
        return getDataTable(list);
    }

    /**
     * 导出规定时间段列表
     */
    @PreAuthorize("@ss.hasPermi('business:time:export')")
    @Log(title = "规定时间段", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BookTime bookTime)
    {
        List<BookTime> list = bookTimeService.selectBookTimeList(bookTime);
        ExcelUtil<BookTime> util = new ExcelUtil<BookTime>(BookTime.class);
        return util.exportExcel(list, "time");
    }

    /**
     * 获取规定时间段详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:time:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bookTimeService.selectBookTimeById(id));
    }

    /**
     * 新增规定时间段
     */
    @PreAuthorize("@ss.hasPermi('business:time:add')")
    @Log(title = "规定时间段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookTime bookTime)
    {
        return toAjax(bookTimeService.insertBookTime(bookTime));
    }

    /**
     * 修改规定时间段
     */
    @PreAuthorize("@ss.hasPermi('business:time:edit')")
    @Log(title = "规定时间段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookTime bookTime)
    {
        return toAjax(bookTimeService.updateBookTime(bookTime));
    }

    /**
     * 删除规定时间段
     */
    @PreAuthorize("@ss.hasPermi('business:time:remove')")
    @Log(title = "规定时间段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bookTimeService.deleteBookTimeByIds(ids));
    }
}
